type EventCallback = (...args: any[]) => void;

export class EventManager {
    private static _instance: EventManager;
    public static get instance(): EventManager {
        if (!this._instance) {
            this._instance = new EventManager();
        }
        return this._instance;
    }

    private constructor() {}

    private listeners: Map<string, Set<EventCallback>> = new Map();

    public on(event: string, callback: EventCallback): void {
        if (!this.listeners.has(event)) {
            this.listeners.set(event, new Set());
        }
        this.listeners.get(event)!.add(callback);
    }

    public off(event: string, callback: EventCallback): void {
        this.listeners.get(event)?.delete(callback);
    }

    public emit(event: string, ...args: any[]): void {
        this.listeners.get(event)?.forEach(cb => cb(...args));
    }

    public offAll(event: string): void {
        this.listeners.delete(event);
    }
} 